Allow Pending Members to see non-member content#475
Open
kimwhite wants to merge 1 commit into
Open
Conversation
This is used to modify the behavior described here: strangerstudios/pmpro-approvals#192 This recipe allow the pending member to view non-member content block or shortcode content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is used to modify the behavior described here: strangerstudios/pmpro-approvals#192
This recipe allow the pending member to view non-member content block or shortcode content.
The final version keeps the original behavior but adds a few safeguards and makes the membership-level check more flexible.
Changes from the Original
Added an admin check earlier in the function
The original snippet skipped admin requests after several other checks.
The final version exits immediately on admin requests, avoiding unnecessary processing.
Made the PMPro page check safer
The original code used
is_page( $pmpro_pages ).The final version only runs the page check after WordPress has finished loading the current page
(did_action( 'wp' ))anduses array_values( $pmpro_pages )to ensure only page IDs are checked.This prevents issues if the filter runs before the queried page is available.
Added a check to confirm the Approvals Add On is active
The final version verifies that the
PMPro_Approvalsclass exists before attempting to use it.This prevents fatal errors if the Add On is deactivated.
Improved detection of "non-member content" checks
The original snippet only handled cases where
$levelswas an array containing a single value of 0.The final version also supports checks where
$levelsis passed directly as0or'0'.This makes the snippet compatible with more ways developers may call
pmpro_hasMembershipLevel().Simplified the approval check
The original version created an instance of the Approvals class before checking the member status.
The final version calls
PMPro_Approvals::isPending()directly, which is cleaner and easier to read.Result
The functionality remains the same: users with a single pending approval level will see content intended for non-members.
The final version is more defensive, handles additional edge cases, and is less likely to cause issues when used alongside custom code or future PMPro updates.